package cn.swust.designpatternlearningplatform.dao.sql;

import cn.swust.designpatternlearningplatform.domain.entity.Student;
import org.apache.ibatis.jdbc.SQL;

public class ClassManagementDaoSql {
    /**
      * @return String
     * @author wang
     * description 获取学期信息
     * date 2023/4/24 10:41
     */
      public String getSemester(String teacherAccount){
          return new SQL(){
              {
                  SELECT("semester");
                  FROM("student");
                  WHERE("teacher_account=#{teacherAccount}");
              }
          }.toString();
      }
      /**
       * @param semester:
        * @return String
       * @author wang
       * description 通过学期查询该学期下的学生
       * date 2023/4/24 10:44
       */
      public String getClassNUmber(String semester,String teacherAccount){
          return new SQL(){
              {
                  SELECT("class_number");
                  FROM("student");
                  WHERE("semester=#{semester}","teacher_account=#{teacherAccount}");
              }
          }.toString();
      }
      /**
       * @param classNumber:
      	 * @param teacherAccount:
      	 * @param semester:
        * @return String
       * @author wang
       * description 通过班级码分页查找学生信息
       * date 2023/4/24 12:13
       */
      public String getList(String classNumber, String semester,String teacherAccount){
          return new SQL(){
              {
                  SELECT("student_name","student_number","place_of_class","class_and_grade","college","rework_mark","payment_status","school_time");
                  FROM("student");
                  WHERE("class_number=#{classNumber}","semester=#{semester}","teacher_account=#{teacherAccount}");
              }
          }.toString();
      }
      /**
       * @param teacherAccount:
      	 * @param semester:
        * @return String
       * @author wang
       * description 获取所有学生的信息
       * date 2023/4/24 12:16
       */
      public String getAllList(String semester,String teacherAccount){
          return new SQL(){
              {
                  SELECT("student_name","student_number","place_of_class","class_and_grade","college","rework_mark","payment_status","school_time");
                  FROM("student");
                  WHERE("semester=#{semester}","teacher_account=#{teacherAccount}");
              }
          }.toString();
      }
//      /**
//       * @param teacherAccount:
//      	 * @param classNumber:
//      	 * @param semester:
//        * @return String
//       * @author wang
//       * description 新建班级
//       * date 2023/4/25 21:38
//       */
//      public String BuildClass(String teacherName,String teacherAccount, String classNumber, String semester){
//          return new SQL(){
//              {
//                  INSERT_INTO("class_information");
//                  VALUES("class_number","#{classNumber}");
//                  VALUES("teacher_account","#{teacherAccount}");
//                  VALUES("semester","#{semester}");
//                  VALUES("teacher_name","#{teacherName}");
//              }
//          }.toString();
//      }
      /**
       * @param student:
        * @return String
       * @author wang
       * description 添加学生
       * date 2023/4/26 13:24
       */
      public  String AddStudent(Student student){
          String classNumber=student.getClassNumber();
          String schoolTime=student.getSchoolTime();
          String placeOfClass=student.getPlaceOfClass();
          String studentNumber=student.getStudentNumber();
          String studentPassword=student.getStudentPassword();
          String studentName=student.getStudentName();
          String classAndGrade=student.getClassAndGrade();
          Integer grade=student.getGrade();
          String college=student.getCollege();
          String major=student.getMajor();
          String reworkMark=student.getReworkMark();
          String paymentStatus=student.getPaymentStatus();
          String teacherAccount=student.getTeacherAccount();
          String semester=student.getSemester();
          return new SQL(){
              {
                  INSERT_INTO("student");
                  VALUES("class_number","#{classNumber}");
                  VALUES("school_time","#{schoolTime}");
                  VALUES("place_of_class","#{placeOfClass}");
                  VALUES("student_number","#{studentNumber}");
                  VALUES("student_password","#{studentPassword}");
                  VALUES("student_name","#{studentName}");
                  VALUES("class_and_grade","#{classAndGrade}");
                  VALUES("grade","#{grade}");
                  VALUES("college","#{college}");
                  VALUES("major","#{major}");
                  VALUES("rework_mark","#{reworkMark}");
                  VALUES("payment_status","#{paymentStatus}");
                  VALUES("teacher_account","#{teacherAccount}");
                  VALUES("semester","#{semester}");
              }
          }.toString();
      }
      public String DeleteClass(String semester, String classNumber, String teacherAccount){
          return  new SQL(){
              {
                  DELETE_FROM("student");
                  WHERE("semester=#{semester}","class_number=#{classNumber}","teacher_account=#{teacherAccount}");
              }
          }.toString();
      }
      public String DeleteStudent(String s){
          return new SQL(){
              {
                  DELETE_FROM("student");
                  WHERE("student_number=#{s}");
              }
          }.toString();
      }
}
